package com.company.chatting;

import com.company.utils.MyException;

import java.io.ObjectInputStream;
import java.net.Socket;

/**
 * @Auther Xue
 * @Date 2021/4/28
 * @Version 1.0
 * @Desc    服务器接收数据
 */
public class ServerListen implements Runnable {
private Socket socket;

    public ServerListen(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
            while (true){
                System.out.println(ois.readObject());
            }
        } catch (Exception e) {
            MyException.logExceptionMessage(e);
        }finally {
            try {
                socket.close();
            }catch (Exception e){
                MyException.logExceptionMessage(e);
            }
        }
    }
}
